package reflection;

import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

import java.lang.reflect.Method;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * Description:反射主要类学习
 * User:22954
 * Date:2024-04-12
 * Time:12:41
 */
public class MainClass {
    /*
    Class
    reflect.Method
    reflect.Field
    reflect.Constructor
     */
    public static void main(String[] args) throws Exception{
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/reflection/re.properties"));
        String classfullpath = properties.get("classfullpath").toString();
        String age = properties.get("age").toString();
        String method = properties.get("method").toString();

        Class<?> aClass = Class.forName(classfullpath);
        Object o = aClass.getDeclaredConstructor().newInstance();
        System.out.println(o.getClass());

        Method aClassMethod = aClass.getMethod(method);
        System.out.println(aClassMethod.toString());
        aClassMethod.invoke(o);

        Field aClassField = aClass.getField("age");
        Field age1 = aClass.getDeclaredField("name");
        age1.setAccessible(true);
        System.out.println(aClassField.toString());
        System.out.println(aClassField.get(o));

        Constructor<?> constructor = aClass.getConstructor();
        System.out.println(constructor);
        Constructor<?> constructor1 = aClass.getConstructor(String.class);
        System.out.println(constructor1);
    }
}
